

//
//  LeeDailyTasksViewController.m
//  firstpoint
//
//  Created by 李雪虎 on 2017/8/2.
//  Copyright © 2017年 xzcysoft. All rights reserved.
//

#import "LeeDailyTasksViewController.h"
#import "LeeNewTaskCellTableViewCell.h"
@interface LeeDailyTasksViewController ()<UITableViewDelegate,UITableViewDataSource>

@property(nonatomic,strong)UITableView *tabelView;
@property(nonatomic,strong)NSArray *bigArr;

@end

@implementation LeeDailyTasksViewController

- (void)viewDidLoad {
    self.title = @"日常任务";
    self.view.backgroundColor = [UIColor whiteColor];
    [super viewDidLoad];
    [self addMyFavoritesTableView];
    [self addHttpURL];
    // Do any additional setup after loading the view.
}
//添加表视图
-(void)addMyFavoritesTableView{
    //表格
    _tabelView = [[UITableView alloc]initWithFrame:CGRectMake(0, 64, width_screen, height_screen-64) style:UITableViewStyleGrouped];
    _tabelView.backgroundColor = [UIColor clearColor];
    _tabelView.showsVerticalScrollIndicator = NO;//隐藏滑动条
    //    _tabelView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tabelView.separatorColor = COLOR(229, 230, 231, 1);//分割线颜色
    _tabelView.delegate = self;
    _tabelView.dataSource = self;
    [_tabelView registerNib:[UINib nibWithNibName:@"LeeNewTaskCellTableViewCell" bundle:nil] forCellReuseIdentifier:@"OenCell"];
    [self.view addSubview:_tabelView];
    
}
#pragma mark --tableView 代理方法
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 100;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _bigArr.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}
//cell内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    LeeNewTaskCellTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"OenCell"];
    cell.titleLbale.text = [NSString stringWithFormat:@"%@",_bigArr[indexPath.row][@"title"]];
     cell.contenLabel.textAlignment = NSTextAlignmentLeft;
    [cell.completeBtn addTarget:self action:@selector(completeBtnClicke:) forControlEvents:UIControlEventTouchUpInside];
    if (indexPath.row==2) {
        cell.contenLabel.text = @"每购买一次商品获得奖励";
        cell.instructionsLabel.text = @"可购买多个";
    }else if (indexPath.row==1){
        cell.contenLabel.text = @"每注册一个好友获得奖励";
        cell.instructionsLabel.text = @"可邀请多个";
    }else if (indexPath.row==0){
        cell.contenLabel.text = @"每日首次分享有效";
        cell.instructionsLabel.text = @"";
    }
    return cell;
    
}
#pragma mark---按钮点击事件
-(void)completeBtnClicke:(UIButton *)button{
    [self.navigationController popToRootViewControllerAnimated:YES];
}
//cell 分割线 两端封头 实现这个两个方法 1
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}
-(void)addHttpURL{
    //日常任务
    NSString * bigURL = [NSString stringWithFormat:@"%@%@",LINK_BASE_URL(@"task/dailyTaskList.api?access_token="),NSUD_Obj(@"token")];
    [HTTPURL postRequest:bigURL parameters:@{} success:^(NSURLSessionDataTask *task, id responseObject) {
        NSLog(@"%@",responseObject);
        if ([responseObject[@"retFlag"]integerValue]==1) {
            _bigArr = [NSArray array];
            _bigArr = (NSArray *)[PublicTools dictionaryWithJsonString:responseObject[@"data"]];
            [_tabelView reloadData];
        }
    } filure:^(NSURLSessionDataTask *task, id error) {
        NSLog(@"%@",error);
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
